<?php

namespace app\admin\controller;

use think\Controller;
use think\Db;
use app\common\service\SysLogService;

class Graphquery extends Controller
{
    public function allfiles()
    {
        $data = request()->post();
        $page = isset($data['page']) ? $data['page'] : 1;
        $limit = isset($data['limit']) ? $data['limit'] : 10;
        $length = $limit;
        //$page = 2;
        if (empty($data['page'])) {
            $page = 0;
        } else {
            $page = $data['page'] - 1;
        }
        $offset = $page * $length;
        $map = array();

        $map = [];
        $map['zstp_is_delete'] = '0';
        // $map['ocr_status'] = array("=", 1);

        if (!empty($data['dh'])) {
            $map['dh'] = array("=", $data['dh']);
        }

        if (!empty($data['content'])) {
            $map['content'] = ['like', '%' . $data['content'] . '%'];
        }

        if (!empty($data['bgqx'])) {
            $map['bgqx'] = array("=", $data['bgqx']);
        }


        if (!empty($data['mj'])) {
            $map['mj'] = array("=", $data['mj']);
        }

        if (!empty($data['lbh'])) {
            $map['lbh'] = array("=", $data['lbh']);
        }

        if (!empty($data['qzh'])) {
            $map['qzh'] = array("=", $data['qzh']);
        }

        if (!empty($data['sj'])) {
            $map['sj'] = array("=", $data['sj']);
        }

        if (!empty($data['tm'])) {
            $map['tm'] = array("=", $data['tm']);
        }

        if (!empty($data['wjbh'])) {
            $map['wjbh'] = array("=", $data['wjbh']);
        }

        if (!empty($data['wz'])) {
            $map['wz'] = array("=", $data['wz']);
        }

        if (!empty($data['ztc'])) {
            $map['ztc'] = array("=", $data['ztc']);
        }

        $count = Db::table('zstp_article')
            ->where($map)
            ->count();

        $list = Db::table('zstp_article')
            ->where($map)
            ->page($page, $limit)
            ->order('id desc')
            ->select();

        return json(array(
            "code" => 200,
            "data" => array("resultList" => $list),
            "totalCount" => $count,
        ));
    }

    public function deldelArticleById(){
        $data = request()->post();
        $id = $data['id'];
        $result = Db::table('zstp_article')->where('id', $id)->update(['zstp_is_delete' => 1]);

        if($result){

            $sysLogService = new SysLogService();
            $tm = Db::table('zstp_article')->where('id', $id)->value('tm');
            $result =  $sysLogService->addLog('删除文书('.$tm.')', $id, 3, '文书id:'.$id);
            return json(array("code" => 200, "message" => "删除成功"));

        }else{
            return json(array("code" => 400, "message" => "删除失败"));
        }

    }

    public function deldelArticleByIds(){
        $data = request()->post();
        $ids = isset($data['ids']) ? $data['ids'] : '';
        
        if (empty($ids)) {
            return json(['code' => 400, 'message' => '参数错误']);
        }
    

        $result = Db::table('zstp_article')->where('id', 'in', $ids)->update(['zstp_is_delete' => 1]);

        if($result){
            $sysLogService = new SysLogService();
            $ids=implode(',', $ids);
            $result =  $sysLogService->addLog('删除文书id('.$ids.')', $ids, 3, '文书id:'.$ids);
            return json(array("code" => 200, "message" => "删除成功"));
        }else{
            return json(array("code" => 400, "message" => "删除失败"));
        }

        
    }

    public function getViewDocumentById(){
        $data = request()->post();
        $id = isset($data['id']) ? $data['id'] : '';

        if (empty($id)) {
            return json(['code' => 400, 'message' => '参数错误']);
        }

        $doc = Db::table('zstp_article')
            ->where('id', $id)
            ->find();

            $data=$doc;
            // var_dump($doc);

            $serverIp = config("kgFilePath");

            $double_layer_pdf = $serverIp ."{$doc['double_layer_pdf']}";
        
            $doc["double_layer_pdf"]= $double_layer_pdf;

            $list = array();


            //唯一标识
    
    
            //档号
            $list[] = array("key" => "档号", "value" =>$data['dh']);
    
            //主题词
    
    
            $list[] = array("key" => "主题词", "value" =>$data['ztc']);
    
            //密级
    
    
            $list[] = array("key" => "密级", "value" =>$data['mj']);
    
            //保管期限
    
    
            $list[] = array("key" => "保管期限", "value" =>$data['bgqx']);
    
            //全宗号
    
    
            //分类号
    
            $list[] = array("key" => "分类号", "value" =>$data['flh']);
    
            //案卷号
    
    
            $list[] = array("key" => "案卷号", "value" =>$data['ajh']);
    
            //件号
    
    
            $list[] = array("key" => "件号", "value" =>$data['jh']);
    
            //关键词
    
    
            $list[] = array("key" => "关键词", "value" =>$data['gjc']);
    
            //类别号
    
    
            $list[] = array("key" => "类别号", "value" =>$data['lbh']);
    
            //文种
    
            $list[] = array("key" => "文种", "value" =>$data['wz']);
    
            //时间
    
    
            $list[] = array("key" => "时间", "value" =>$data['sj']);
    
            //题名
    
    
            $list[] = array("key" => "题名", "value" =>$data['tm']);
    
            //文件编号
    
    
            $list[] = array("key" => "文件编号", "value" =>$data['wjbh']);
    
            //载体类型
    
    
            $list[] = array("key" => "载体类型", "value" =>$data['ztlx']);
    
            //载体数量
    
            $list[] = array("key" => "载体数量", "value" =>$data['ztsl']);
    
            //载体单位
    
    
            $list[] = array("key" => "载体单位", "value" =>$data['ztdw']);
    
            //载体规格
    
    
            $list[] = array("key" => "载体规格", "value" =>$data['ztgg']);
    
            //责任者
    
    
            $list[] = array("key" => "责任者", "value" =>$data['zrz']);
    
            //微缩号
    
            $list[] = array("key" => "缩微号", "value" =>$data['swh']);
    
            //档案馆号
    
    
            $list[] = array("key" => "档案馆代号", "value" =>$data['dagdh']);
    
            //数据类型
    
    
            $list[] = array("key" => "数据类型", "value" =>$data['sjlx']);
    
            //附注
    
    
            $list[] = array("key" => "附注", "value" =>$data['fz']);
    
    
    
           $doc['list'] = $list;

      

            



        return json(['code' => 200, 'message' => '获取成功', 'data' => $doc]);
        
    }


}
